package com.youhong.teethcare;


import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.youhong.teethcare.utils.ScreenUtils;

public class BaseActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      /*  if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
*/
    }



    @Override
    public void startActivity(Intent intent) {
        // TODO Auto-generated method stub
        super.startActivity(intent);
        overridePendingTransition(R.anim.push_right_in, R.anim.push_left_out);
    }

    public void startActivity(Class cls) {
        // TODO Auto-generated method stub
        super.startActivity(new Intent(this,cls));
        overridePendingTransition(R.anim.push_right_in, R.anim.push_left_out);
    }
    public void startActivity(String key,int value ,Class cls) {
        // TODO Auto-generated method stub
        Intent intent=new Intent(this,cls);
        intent.putExtra(key,value);
        super.startActivity(intent);
        overridePendingTransition(R.anim.push_right_in, R.anim.push_left_out);
    }
    @Override
    public void finish() {
        // TODO Auto-generated method stub
        super.finish();
        if (!(this instanceof MainActivity)) {
            overridePendingTransition(R.anim.push_left_in,
                    R.anim.push_right_out);
        }
    }


    private static long lastClickTime;

    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (0 < timeD && timeD < 400) {
            return true;
        }
        lastClickTime = time;
        return false;
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            if (isFastDoubleClick()) {
                return true;
            }
        }
        return super.dispatchTouchEvent(ev);
    }
    protected void initStatusBar(int color,boolean isDark){
        ScreenUtils.setStatusBarColor(this, color);
        setStatusBarDarkMode(isDark);
    }
    protected void setStatusBarColor(int color){
        ScreenUtils.setStatusBarColor(this, color);
    }
    protected void setStatusBarDarkMode(boolean dark){
        View decor = getWindow().getDecorView();
        if (dark) {
            decor.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decor.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }
}